home *** CD-ROM | disk | FTP | other *** search
- /**
- * Single_Space_Buffer.bsh - A Beanshell macro for jEdit that
- * converts a buffer from being double-spaced (where every second
- * line is blank) to single-spaced, by removing each second line -
- * but only if they're all blank.
- *
- * Copyright (C) 2004 Ollie Rutherfurd <oliver@rutherfurd.net>
- *
- * $Id: Single_Space_Buffer.bsh,v 1.1 2004/03/19 15:58:00 spestov Exp $
- */
-
- void singleSpaceBuffer(View view)
- {
- Buffer buffer = view.getBuffer();
- int line = 1; // start on second line
- Vector lines = new java.util.Stack();
-
- try
- {
- while(line < buffer.getLineCount())
- {
- if(buffer.getLineText(line).equals(""))
- lines.addElement(new Integer(line));
- else
- {
- StringBuffer msg = new StringBuffer();
- msg.append(buffer.getPath() + " doesn't appear to be double-spaced:\n");
- msg.append("Line " + (line + 1) + " isn't blank.");
- Macros.error(view, msg.toString());
- return;
- }
- line += 2;
- }
- while(!lines.empty())
- {
- Integer lineno = (Integer)lines.pop();
- int offset = buffer.getLineStartOffset(lineno.intValue());
- buffer.remove(offset-1,1);
- }
- }
- finally
- {
- if(buffer.insideCompoundEdit())
- buffer.endCompoundEdit();
- }
- }
-
- singleSpaceBuffer(view);
-
- /*
-
- <listitem>
- <para><filename>Single_Space_Buffer.bsh</filename></para>
- <abstract><para>
- Removes every second line, if they are all blank.
- </para></abstract>
- </listitem>
-
- */
-